let resData = {
  "data": {
    "res_data": [{
        "name": "一、履历材料",
        "id": "01",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "1999年制干部履历表",
            "id": "1",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "01",
            "isPart": null
          },
          {
            "name": "1999年制干部履历表",
            "id": "2",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "01",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "二、自传材料",
        "id": "02",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": null,
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "三、鉴定、考核材料",
        "id": "03",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "社会实践活动登记表",
            "id": "3",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          },
          {
            "name": "1999年度考核登记表",
            "id": "4",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          },
          {
            "name": "2006年度考核登记表",
            "id": "5",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          },
          {
            "name": "2017年度考核登记表",
            "id": "6",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          },
          {
            "name": "2018年度考核登记表",
            "id": "7",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          },
          {
            "name": "2019年度考核登记表",
            "id": "8",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "03",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "四、学历学位、职称、学术、培训等材料",
        "id": "04",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "4-1 学历学位材料",
            "id": "0401",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": [{
                "name": "高中毕业生登记表",
                "id": "9",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "高校招生考生报考登记表",
                "id": "10",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": [{
                    "name": "体格检查表",
                    "id": "44",
                    "data": null,
                    "flag": "1",
                    "relationState": null,
                    "createDa": null,
                    "spell": null,
                    "children": null,
                    "parentId": "10",
                    "isPart": null
                  },
                  {
                    "name": "体育合格情况登记卡",
                    "id": "45",
                    "data": null,
                    "flag": "1",
                    "relationState": null,
                    "createDa": null,
                    "spell": null,
                    "children": null,
                    "parentId": "10",
                    "isPart": null
                  }
                ],
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "中国海洋大学成绩单",
                "id": "11",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": [{
                  "name": "档案清理整理复制验收登记表",
                  "id": "46",
                  "data": null,
                  "flag": "1",
                  "relationState": null,
                  "createDa": null,
                  "spell": null,
                  "children": null,
                  "parentId": "11",
                  "isPart": null
                }],
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "中国海洋大学毕业生登记表",
                "id": "12",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "中国海洋大学本科毕业证书",
                "id": "13",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "山东大学成绩单",
                "id": "14",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "山东大学毕业研究生登记表",
                "id": "15",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              },
              {
                "name": "山东大学硕士研究生毕业证书",
                "id": "16",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0401",
                "isPart": null
              }
            ],
            "parentId": "04",
            "isPart": null
          },
          {
            "name": "4-2专业技术职务材料",
            "id": "0402",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": [{
              "name": "会计中级专业资格证书",
              "id": "17",
              "data": null,
              "flag": "1",
              "relationState": null,
              "createDa": null,
              "spell": null,
              "children": null,
              "parentId": "0402",
              "isPart": null
            }],
            "parentId": "04",
            "isPart": null
          },
          {
            "name": "4-3科研学术材料",
            "id": "0403",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "04",
            "isPart": null
          },
          {
            "name": "4-4 培训材料",
            "id": "0404",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "04",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "五、政审材料",
        "id": "05",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "关于其父亲的政审证明",
            "id": "18",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "05",
            "isPart": null
          },
          {
            "name": "关于其母亲的政审证明",
            "id": "19",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "05",
            "isPart": null
          },
          {
            "name": "干部基本信息审核确认表",
            "id": "20",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "05",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "六、党团材料",
        "id": "06",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "入团志愿书",
            "id": "21",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "06",
            "isPart": null
          },
          {
            "name": "入党志愿书",
            "id": "22",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "06",
            "isPart": null
          },
          {
            "name": "入党申请书",
            "id": "23",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "06",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "七、奖励材料",
        "id": "07",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
          "name": "奖励审批表",
          "id": "24",
          "data": null,
          "flag": "1",
          "relationState": null,
          "createDa": null,
          "spell": null,
          "children": null,
          "parentId": "07",
          "isPart": null
        }],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "八、处分材料",
        "id": "08",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "关于解除其行政警告处分的决定",
            "id": "25",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "08",
            "isPart": null
          },
          {
            "name": "关于给予其行政警告处分的决定",
            "id": "26",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "08",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "九、工资、任免、出国、会议等材料",
        "id": "09",
        "data": null,
        "flag": "0",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "9-1 工资材料",
            "id": "0908",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": [{
                "name": "高校毕业生转正定级审批表",
                "id": "27",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资变动审批表",
                "id": "28",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资变动审批表",
                "id": "29",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资调整审批表",
                "id": "30",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资调整审批表",
                "id": "31",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资调整审批表",
                "id": "32",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资调整审批表",
                "id": "33",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              },
              {
                "name": "工资调整审批表",
                "id": "34",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0908",
                "isPart": null
              }
            ],
            "parentId": "09",
            "isPart": null
          },
          {
            "name": "9-2 任免材料",
            "id": "0909",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": [{
                "name": "干部任免审批表",
                "id": "35",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "36",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "37",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "38",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "39",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "40",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "41",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              },
              {
                "name": "干部任免审批表",
                "id": "42",
                "data": null,
                "flag": "1",
                "relationState": null,
                "createDa": null,
                "spell": null,
                "children": null,
                "parentId": "0909",
                "isPart": null
              }
            ],
            "parentId": "09",
            "isPart": null
          },
          {
            "name": "9-3出国（境）审批材料",
            "id": "0910",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": [{
              "name": "因私出国（境）审批表",
              "id": "43",
              "data": null,
              "flag": "1",
              "relationState": null,
              "createDa": null,
              "spell": null,
              "children": null,
              "parentId": "0910",
              "isPart": null
            }],
            "parentId": "09",
            "isPart": null
          },
          {
            "name": "9-4会议代表材料",
            "id": "0911",
            "data": null,
            "flag": "0",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "09",
            "isPart": null
          }
        ],
        "parentId": "ZA",
        "isPart": null
      },
      {
        "name": "高校招生考生报考登记表",
        "id": "10",
        "data": null,
        "flag": "1",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
            "name": "体格检查表",
            "id": "44",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "10",
            "isPart": null
          },
          {
            "name": "体育合格情况登记卡",
            "id": "45",
            "data": null,
            "flag": "1",
            "relationState": null,
            "createDa": null,
            "spell": null,
            "children": null,
            "parentId": "10",
            "isPart": null
          }
        ],
        "parentId": "0401",
        "isPart": null
      },
      {
        "name": "中国海洋大学成绩单",
        "id": "11",
        "data": null,
        "flag": "1",
        "relationState": null,
        "createDa": null,
        "spell": null,
        "children": [{
          "name": "档案清理整理复制验收登记表",
          "id": "46",
          "data": null,
          "flag": "1",
          "relationState": null,
          "createDa": null,
          "spell": null,
          "children": null,
          "parentId": "11",
          "isPart": null
        }],
        "parentId": "0401",
        "isPart": null
      }
    ],
    "res_code": "0000"
  },
  "code": 0,
  "msg": "success"
}

const findTreeItem = (list, tid) => {
  let obj = {}
  for (let i = 0; i < list.length; i++) {
    const item = list[i];
    if (tid === String(item.id)) {
      obj = item
      break
    }
    if (Array.isArray(item.children) && item.children.length > 0) {
      obj = findTreeItem(item.children, tid)
    }
  }
  return obj
}

// 获取选中对应得树
const findTreeList = (list, tids) => {
  return tids.map(e => {
    return findTreeItem(list, e);
  })
}

// 获取树得id
const fundTreeListIds = (treelist, tids) => {
  let treeList = findTreeList(treelist, tids);
  return treeList.reduce((prv, cur) => {
    if (Array.isArray(cur.children) && cur.children.length > 0) {
      return prv.concat(cur.children.reduce((cprv, child) => {
        return cprv.concat(child.id);
      }, []))
    } else {
      return prv.concat(cur.id);
    }
  }, [])
}

/**
 * 获取对应的 需要获取图片的，对应的树型id 
 * @param {*} constents 选择的内容ids
 * @param {*} tree 树型数据
 */
// export const getApplyContentsArrayByTree = (constents, ttree = []) => {
const getApplyContentsArrayByTree = (constents, ttree = []) => {
  // 这个是 上面查阅内容的cid 对应的，treeids 是 树结构的id 数组
  // 你知道对应的是那几个, 直接映射到这里，我们就知道哪个对应哪个了
  let tree = JSON.parse(JSON.stringify(ttree))

  // 这个后端没有给我们对应的的树型数据id
  // 比如到线上了，树型数据多了，还有很多，需要手动写死的这个，就类似你刚写的 if ... else if ...
  let contentMap = [{
      cid: '01',
      treeIds: ['01']
    },
    {
      cid: '02',
      treeIds: ['02']
    },
    {
      cid: '03',
      treeIds: ['03']
    },
    {
      cid: '04',
      treeIds: ['0401']
    },
    {
      cid: '05',
      treeIds: ['0402']
    },
    {
      cid: '06',
      treeIds: ['0403']
    },
    {
      cid: '07',
      treeIds: ['0404']
    },
    {
      cid: '08',
      treeIds: ['05']
    },
    {
      cid: '09',
      treeIds: ['06']
    },
    {
      cid: '10',
      treeIds: ['07']
    },
    {
      cid: '11',
      treeIds: ['08']
    },
    {
      cid: '12',
      treeIds: ['0908']
    },
    {
      cid: '13',
      treeIds: ['0909']
    },
    {
      cid: '14',
      treeIds: ['0910']
    },
    {
      cid: '15',
      treeIds: ['0911']
    },
    {
      cid: '16',
      treeIds: ['10', "11"]
    },
    // ...
  ]

  // 得到需要树型的ids
  let selectTreeIds = contentMap.filter(f => constents.includes(f.cid))
    .reduce((prv, cur) => {
      prv.push(...cur.treeIds)
      return prv
    }, [])

  let lists = findTreeList(resData.data.res_data, selectTreeIds)
  // console.log('selectTreeIds', selectTreeIds, lists)
  let treeids = fundTreeListIds(resData.data.res_data, selectTreeIds)
  console.log('treeids', treeids)
}

getApplyContentsArrayByTree(['01', '02', '03', '10', '16'])
